<?php
/**
 * @Author: king
 * @Last Modified by:   king
 * Date: 2018/6/6
 * Time: 17:38
 */
namespace App\Models\Api;
use App\Exceptions\ApiException;
use App\Models\Api\Base;
use Illuminate\Database\Eloquent\Model;
use Cache;
class PushServer extends Base
{
    protected $table = 'push_server';

    /**
     *
     * @param array $map
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws ApiException
     */
    public function getPushServer($map = [])
    {
        $id = $map['id'];
        $data = false;
        if (intval($this->cache_on) >= 1 && Cache::has('push_server_'.$id)) {
            $data = Cache::get('push_server_'.$id);
        }
        if ($data === false) {
            try {
               
                $data = $this->where(['id'=>$id])->first(['id','title','content' ,'alert');

                $data = json_decode(json_encode($data, true), true);

                Cache::set('push_server_'.$id, $data, 86400);

            } catch (\Exception $e) {

                throw new ApiException('推送获取失败', 200, config('code.error'));
            }
        }
        return $data;
    }
}
